<template>
  <div class="guotukongjian">
    <div class="guotukongjian_top">
      <div class="guotukongjian_top_text">
        国土空间规划三区三线
      </div>
      <!-- <div class="toexcel">
        <el-button @click="exportExcel1" type="primary" class="excel_button">导出</el-button>
      </div> -->
    </div>
    <div class="table">
      <el-table
        class="tableData1"
        :data="tableData1"
        border
        height="335"
        style="width: 100%; margin-top: 10px;"
        row-key="id"
        default-expand-all
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
        <el-table-column
          prop="leibie.value"
          min-width="80px"
          align="center"
          label="类别"
        >
        </el-table-column>
        <el-table-column
          prop="Ha.value"
          align="center"
          min-width="55px"
          label="面积(ha)"
        >
        </el-table-column>
        <el-table-column
          prop="Mu.value"
          align="center"
          min-width="55px"
          label="面积(亩)"
        >
        </el-table-column>
        <el-table-column
          prop="zhanbi.value"
          align="center"
          min-width="50px"
          label="占比(%)"
        >
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
// import {exportExcel} from "../../../../../tools/validate"
export default {
  data() {
    return {
      // 表格的数据
      tableData1: [
        {
          leibie: {
            value: "永久基本农田",
          },
          Ha: {
            value: 0,
          },
          Mu: {
            value: 0,
          },
          zhanbi: {
            value: 0,
          },
        },
        {
          leibie: {
            value: "生态保护红线",
          },
          Ha: {
            value: 0,
          },
          Mu: {
            value: 0,
          },
          zhanbi: {
            value: 0,
          },
        },
        {
          leibie: {
            value: "城镇开发边界",
          },
          Ha: {
            value: 0,
          },
          Mu: {
            value: 0,
          },
          zhanbi: {
            value: 0,
          },
        },
        {
          leibie: {
            value: "其他",
          },
          Ha: {
            value: 0,
          },
          Mu: {
            value: 0,
          },
          zhanbi: {
            value: 0,
          },
        },
        {
          leibie: {
            value: "合计",
          },
          Ha: {
            value: 0,
          },
          Mu: {
            value: 0,
          },
          zhanbi: {
            value: 0,
          },
        },
      ],

      // 合计ha的值
      haAll: 0,
      // 合计mu的值
      muAll: 0,
      // 合计占比的值
      zhanbiAll: 0,
    };
  },
  methods: {
    // 接口请求土地存储数据并处理
    getTudiscData() {
      console.log(this.gtkjghData, "国土空间规划数据");
      // 将请求的数据赋值到tableData1中
      this.tableData1[0].Ha.value = this.gtkjghData.yjjbntHa.value;
      this.tableData1[0].Mu.value = this.gtkjghData.yjjbntMu.value;
      if (Number(this.gtkjghData.yjjbntRatio) > 100) {
        this.tableData1[0].zhanbi.value = 100;
      } else {
        this.tableData1[0].zhanbi.value = this.gtkjghData.yjjbntRatio;
      }

      this.tableData1[1].Ha.value = this.gtkjghData.shtbhhxHa.value;
      this.tableData1[1].Mu.value = this.gtkjghData.shtbhhxMu.value;
      if (this.gtkjghData.shtbhhxRatio > 100) {
        this.tableData1[1].zhanbi.value = 100;
      } else {
        this.tableData1[1].zhanbi.value = this.gtkjghData.shtbhhxRatio;
      }

      this.tableData1[2].Ha.value = this.gtkjghData.czhkfbjHa.value;
      this.tableData1[2].Mu.value = this.gtkjghData.czhkfbjMu.value;
      if (this.gtkjghData.czhkfbjRatio > 100) {
        this.tableData1[2].zhanbi.value = 100;
      } else {
        this.tableData1[2].zhanbi.value = this.gtkjghData.czhkfbjRatio;
      }

      console.log(this.tableData1, "tableData1");

      let num = 0;
      this.tableData1.forEach((item, index) => {
        if (index < this.tableData1.length - 1) {
          num += Number(item.zhanbi.value);
        } else {
          item.zhanbi.value = Number((100 - num).toFixed(1));
        }
      });

      // 计算合计的值
      this.tableData1.forEach((item) => {
        console.log(item, "合计item的值");
        this.haAll += Number(item.Ha.value);
        this.zhanbiAll += Number(item.zhanbi.value);
        this.muAll += Number(item.Mu.value);
      });

      this.tableData1[4].Ha.value = this.haAll.toFixed(3);
      this.tableData1[4].Mu.value = this.muAll.toFixed(2);
      if (Number(this.zhanbiAll.toFixed(0)) > 100) {
        this.tableData1[4].zhanbi.value = 100;
      } else {
        this.tableData1[4].zhanbi.value = this.zhanbiAll.toFixed(0);
      }

      console.log(this.tableData1, "更新后tableData1的值");
    },
    rounding(row, colum) {
      return parseFloat(row[colum.property]).toFixed(2);
    },
    rounding1(row, colum) {
      return parseFloat(row[colum.property]).toFixed(1);
    },

    // // 导出表格
    // exportExcel1(){
    //   exportExcel(".tableData1","国土空间规划三区三线")
    // }
  },
  computed: {
    ...mapState("Sjsx", ["tdscData", "gtkjghData"]),
  },
  watch: {},
  mounted() {
    this.getTudiscData();
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-table,
::v-deep .el-table__expanded-cell {
  background-color: rgba(14, 85, 238, 0.109) !important;
  border: 1px solid #466393cc;
}
::v-deep .el-table__body-wrapper {
  height: 290px !important;
}
// 滚动条的宽度
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
// 滚动条的滑块
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background: linear-gradient(
    180deg,
    rgba(131, 166, 166, 0.1),
    rgba(131, 166, 166, 0.8),
    rgba(131, 166, 166, 0.1)
  );
}
// 滚动条里面的轨道(即背景颜色)
::v-deep .el-table__body-wrapper::-webkit-scrollbar-track {
  // background-color: #5b739b2b;
  background-color: rgba(41, 71, 89, 0.4);
}
::v-deep .el-table__header th,
::v-deep .el-table__header tr {
  // background-color: #17B3A3;
  color: #fff;
}
::v-deep .el-table th,
::v-deep .el-table tr,
::v-deep .el-table td {
  background-color: rgba(251, 251, 251, 0.109) !important;

  border: 0px solid #466393cc;
}
::v-deep .el-table__expand-icon {
  color: #fff;
}
/* 去掉中间数据的分割线 */
::v-deep .el-table__row > td {
  // border: 1px solid #466393cc;
}
/* 去掉上面的线 */
::v-deep .el-table th.is-leaf {
  // border: 1px solid #466393cc;
}
::v-deep .el-table--border th.el-table__cell.gutter:last-of-type {
  border-bottom: 1px solid #466393cc;
}
/* 去掉最下面的那一条线 */
::v-deep .el-table::before {
  height: 0px;
}
::v-deep .el-table__body tr {
  background-color: transparent !important;

  border: 1px solid #466393cc;
}
// .el-table__body tr:hover > td {
//     background-color: transparent !important;

//     border: 0px solid #134087;
// }
::v-deep .el-table td.el-table__cell,
::v-deep .el-table th.el-table__cell.is-leaf {
  border-bottom: 1px solid #466393cc;
  border-left: 1px solid #466393cc;
  font-size: 18px;
}
::v-deep .el-table--border .el-table__cell,
::v-deep
  .el-table__body-wrapper
  .el-table--border.is-scrolling-left
  ~ .el-table__fixed {
  border-right: 0px solid #ebeef5;
  color: #fff;
}
::v-deep .el-table--border::after,
::v-deep .el-table--group::after,
::v-deep .el-table::before {
  content: "";
  position: absolute;
  background-color: #466393cc;
  z-index: 1;
}
::v-deep .el-table th.el-table__cell > .cell {
  padding-left: 5px;
  padding-right: 5px;
}
.guotukongjian {
  margin-bottom: 35px;
  .guotukongjian_top {
    background: url("../../../../../assets/images/home/top.png");
    background-size: cover;
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    .guotukongjian_top_text {
      padding-left: 16px;
      font-family: OPPOSans;
      font-style: normal;
      font-weight: normal;
      font-size: 20px;
      line-height: 24px;
      color: #ffffff;
    }
    // .toexcel{
    //   .excel_button{
    //     font-size: 12px;
    //     height: 20px;
    //     width: 50px;
    //     display: flex;
    //     align-items: center;
    //     justify-content: center;
    //   }
    // }
  }
}
</style>
